<template>
  <!--招聘管理-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="8">
        <el-button type="primary" @click="tags">招聘月薪管理</el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="16">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              style="margin-right: 10px"
              placeholder="请输入姓名或手机号"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search">
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="create_time"
        label="发布时间"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.nickname"
        label="发布昵称"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.mobile"
        label="发布手机号"
      />
      <el-table-column
        align="center"
        prop="title"
        show-overflow-tooltip
        label="岗位名称"
      />
      <el-table-column
        align="center"
        prop="money"
        show-overflow-tooltip
        label="薪资"
      />
      <el-table-column
        align="center"
        prop="city_data.name"
        show-overflow-tooltip
        label="城市"
      />
      <el-table-column
        align="center"
        prop="end_time"
        show-overflow-tooltip
        label="截止时间"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="status"
        label="状态"
      >
        <template #default="{ row }">
          {{ row.status == 1 ? '正常' : row.status == 2 ? '下架' : '' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="infos(scope)">岗位要求</el-button>
          <el-button
            v-if="scope.row.status == 1"
            type="text"
            @click="outList(scope.row)"
          >
            下架
          </el-button>
          <el-button type="text" @click="delList(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 岗位要求 -->
    <el-dialog title="要求" :visible.sync="dialogDetail">
      <div>{{ workContent }}</div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogDetail = false">
          确 定
        </el-button>
      </div>
    </el-dialog>

    <!-- 月薪 -->
    <el-dialog title="月薪列表" :visible.sync="dialogFormVisible">
      <el-button type="primary" @click="addOnetag()">添加</el-button>
      <el-table
        v-loading="listLoading"
        :data="labels"
        @selection-change="setSelectRows"
      >
        <el-table-column
          align="center"
          show-overflow-tooltip
          label="序号"
          sortable
          type="index"
        />
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="money"
          label="金额"
        />
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="editOnetag(scope)">编辑</el-button>
            <el-button type="text" @click="delOnetag(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page="queryForm.page"
        :page-size="queryForm.list_row"
        :layout="layout"
        :total="totalOnetag"
        @size-change="winSizeChange"
        @current-change="winCurrentChange"
      />
    </el-dialog>

    <!-- 操作月薪 -->
    <el-dialog :title="onetag" :visible.sync="dialogOnetag">
      <el-input v-model="onetagName" clearable />
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogOnetag = false">取 消</el-button>
        <el-button v-show="addtype" type="primary" @click="addtag()">
          确 定
        </el-button>
        <el-button v-show="edittype" type="primary" @click="editTag()">
          确 定
        </el-button>
      </div>
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import {
    getRecruitmentLists,
    delRecruitments,
    outRecruitments,
    getRecruitmentMoneys,
    addRecruitmentMoneys,
    delRecruitmentMoneys,
  } from '@/api/common'

  export default {
    name: 'Recruit',
    data() {
      return {
        user: [],
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
        },
        form: {
          content: '',
        },
        disabled: false,
        listLoading: false,
        list: [],
        labels: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        workContent: '',
        onetagName: '',
        dialogDetail: false,
        dialogFormVisible: false,
        dialogOnetag: false,
        onetagId: 0,
        onetag: '',
        addtype: false,
        edittype: false,
        totalOnetag:'',
      }
    },
    created() {
      this.getData()
    },
    methods: {
      handleDetail() {},
      //搜索
      search() {
        this.getData()
      },
      restart() {
        this.queryForm = []
        this.getData()
      },
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          search_input: this.queryForm.keyword,
        }
        getRecruitmentLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      infos(row) {
        this.dialogDetail = true
        this.workContent = this.list[row.$index].content
      },
      outList(row) {
        let params = {
          id: row.id,
        }
        outRecruitments(params).then((data) => {
          this.$message.success('下架成功！')
          this.getData()
        })
      },
      delList(row) {
        let params = {
          id: row.id,
        }
        delRecruitments(params).then((data) => {
          this.$message.success('删除成功！')
          this.getData()
        })
      },

      tags() {
        this.dialogFormVisible = true
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
        }
        getRecruitmentMoneys(params).then((data) => {
          this.labels = data.data
          this.totalOnetag = data.count
        })
      },
      addOnetag() {
        this.dialogOnetag = true
        this.addtype = true
        this.edittype = false
        this.onetag = '添加月薪'
        this.onetagName = ''
      },
      addtag() {
        let params = {
          data: this.onetagName,
        }
        addRecruitmentMoneys(params).then((data) => {
          this.$message.success('添加成功！')
          this.dialogOnetag = false
          this.tags()
        })
      },
      delOnetag(row) {
        let params = {
          data: row.money,
        }
        delRecruitmentMoneys(params).then((data) => {
          this.$message.success('删除成功！')
          this.tags()
        })
      },
      editOnetag(row) {
        this.dialogOnetag = true
        this.onetag = '修改月薪'
        this.addtype = false
        this.edittype = true
        this.onetagName = this.labels[row.$index].money
        this.onetagId = row.row.money
      },
      editTag(row) {
        let params = {
          re_data: this.onetagName,
          data: this.onetagId,
        }
        editLabels(params).then((data) => {
          this.$message.success('修改成功！')
          this.edittype = false
          this.tags()
        })
      },

      setSelectRows() {},
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getData()
      },
      selectType(e) {
        this.queryForm.types === e.value
      },
      winSizeChange(val) {
        this.queryForm.list_row = val
        this.tags()
      },
      winCurrentChange(val) {
        this.queryForm.page = val
        this.tags()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-button {
    font-size: 14px;
  }
</style>
